//
//  MainViewController.swift
//  weibo2
//
//  Created by xuwzh on 15/10/6.
//  Copyright © 2015年 xuwzh. All rights reserved.
//

import UIKit


/**
    tabBarController    : 控制器，用来编写代码，切换控制器
    tabbar              ：大条
    tabBarItem          : 小项目
    tabBarButton        : item内部的按钮

*/

class MainViewController: UITabBarController {
    
    
    @IBOutlet weak var mainTabBar: MainUITabBar!

    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        //设置底部文字渲染颜色
        tabBar.tintColor=UIColor.orangeColor()
        addChildViewControllers()
        self.mainTabBar.composeButton.addTarget(self, action:"clickCompose", forControlEvents: UIControlEvents.TouchUpInside)
        
        
        
    }
    
    
    
    
    ///添加所有的子视图
  private  func addChildViewControllers() {
       
        addChildViewController("Home", title: "首页", imageName: "tabbar_home")
        
        addChildViewController("Message", title: "消息", imageName: "tabbar_message_center")
        
        addChildViewController("Discover", title: "发现", imageName: "tabbar_message_center")
        
        addChildViewController("Profile", title: "我", imageName: "tabbar_profile")
        
        
    }
    
    
   private func addChildViewController(name: String,title : String,imageName :String) {
        
        let sb=UIStoryboard(name: name, bundle: nil)
        let nav=sb.instantiateInitialViewController() as! UINavigationController
        nav.topViewController?.title=title
        nav.tabBarItem.image=UIImage(named: imageName)
        nav.tabBarItem.selectedImage=UIImage(named: imageName+"_highlighted")
        addChildViewController(nav)
    }
    
    
    
  func clickCompose(){
    
      print("\(__FUNCTION__)")
        
      print("按钮被点击了")
    
    }
    
    
    
}
